package com.sangmo.fts.basic.service;

import com.sangmo.boot.framework.plugin.dataview.crud.service.DelegateViewService;
import com.sangmo.boot.framework.plugin.dataview.crud.service.ViewService;
import com.sangmo.fts.basic.interfaces.BankCreation;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.utils.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CompanyService extends DelegateViewService<Company> {

    @Autowired
    private CompanyEntityService companyEntityService;

    @Override
    protected ViewService<Company> getEntityService() {
        return companyEntityService;
    }

    public Company createBank(Object bo) {
        BankCreation creation = (BankCreation) bo;
        Company entity = new Company();
        entity.setCode(RandomUtils.generateRandomStr(8));
        entity.setType(Company.Type.BANK);
        entity.setName(creation.getName());
        entity.setManager(creation.getManager());
        entity.setPhone(creation.getPhone());
        entity.setRegisteredAddress(creation.getRegisteredAddress());
        entity.setCreditRating(Company.CreditRating.AAA);
        return this.save(entity);
    }

}
